﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAT.Model;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Windows.Forms;
namespace MAT.Controllers
{
    class ctrReportCategory
    {
        private frmReportCategory _frmReportCategory = null;

        public frmReportCategory FrmReportCategory
        {
            get { return _frmReportCategory; }
            set { _frmReportCategory = value; }
        }

        MAT_Context context = MATContext.getContext();
        CommonClass ccl = new CommonClass();

        private bool check(TextBox tb)
        {
            foreach (CATEGORY category in context.CATEGORies.ToList())
            {
                if (tb.Text == category.CATEGORY_NAME)
                    return true;
            }
            MessageBox.Show("Category is wrong!");
            tb.Text = "";
            tb.Focus();
            return false;
        }

        public void btnReportCategory_Click()
        {
            if (check(_frmReportCategory.textBox1))
            {
                ReportDocument cryRpt = new ReportDocument();
                cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportCategory.rpt");

                ccl.automationConnect(cryRpt);
                ccl.report_Parameter(cryRpt, _frmReportCategory.textBox1.Text, "CategoryName");
                _frmReportCategory.crystalReportViewer2.ReportSource = cryRpt;
                _frmReportCategory.crystalReportViewer2.Refresh();
            }
        }


        public void btnReportAllCategory()
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(Application.StartupPath + @"\..\..\Reports\crpReportAllCategory.rpt");
            ccl.automationConnect(cryRpt);
            _frmReportCategory.crystalReportViewer2.ReportSource = cryRpt;
            _frmReportCategory.crystalReportViewer2.Refresh();
        }
        public void btnExport()
        {
            _frmReportCategory.crystalReportViewer2.ExportReport();

        }
        public void btnPrint()
        {
            _frmReportCategory.crystalReportViewer2.PrintReport();
        }
    }

}
